package com.erp.gather.controller;

import com.erp.gather.domain.bo.ErpSellerStoreGroupBo;
import com.erp.gather.domain.vo.ErpSellerStoreGroupVo;
import com.erp.gather.service.IErpSellerStoreGroupService;
import com.ruoyi.ae.api.RemoteAeStoreGroupService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.system.api.RemoteUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户店铺商品分组
 *
 * @author erp
 * @date 2023-11-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/gather/sellerStoreGroup")
public class ErpSellerStoreGroupController extends BaseController {

    private final IErpSellerStoreGroupService iErpSellerStoreGroupService;
    @Resource
    RemoteAeStoreGroupService remoteAeStoreGroupService;

    /**
     * 查询用户店铺商品分组列表
     */
    @GetMapping("/selectStoreGroupByUserId")
    public TableDataInfo<ErpSellerStoreGroupVo> list(ErpSellerStoreGroupBo bo, PageQuery pageQuery) {
        return iErpSellerStoreGroupService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取用户店铺商品分组详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<ErpSellerStoreGroupVo> getInfo(@NotNull(message = "主键不能为空")
                                            @PathVariable Long id) {
        return R.ok(iErpSellerStoreGroupService.queryById(id));
    }

    /**
     * 新增用户店铺商品分组
     */
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpSellerStoreGroupBo bo) {
        return toAjax(iErpSellerStoreGroupService.insertByBo(bo));
    }

    /**
     * 修改用户店铺商品分组
     */
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSellerStoreGroupBo bo) {
        return toAjax(iErpSellerStoreGroupService.updateByBo(bo));
    }

    /**
     * 删除用户店铺商品分组
     *
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpSellerStoreGroupService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 从速卖通获取店铺分组信息
     */
    @GetMapping("/queryStoreGroupList")
    public R<Object> queryStoreGroupList(Long storeId) {
        //TODO Ae相关 转为内部调用 待测试
        return remoteAeStoreGroupService.queryStoreGroupList(storeId);
    }

    /**
     * 创建新的商品分组
     */
    @GetMapping("/createStoreGroup")
    public R<Object> createStoreGroup(String memo, String groupName, Long parentId, Long storeId) {
        //TODO Ae相关 转为内部调用 待测试
        Map<String,Object> map = new HashMap<>();
        map.put("memo",memo);
        map.put("groupName",groupName);
        map.put("parentId",parentId);
        map.put("storeId",storeId);
//        return remoteAeStoreGroupService.createStoreGroup();
        return R.fail();
    }

    @GetMapping("/queryAvailableGroupsByStoreId")
    public R<Object> queryAvailableGroupsByStoreId(Long storeId) {
        return iErpSellerStoreGroupService.queryAvailableGroupsByStoreId(storeId);
    }

    @GetMapping("/createGroupAgain")
    public R<Object> createGroupAgain(Long storeId) {
        return iErpSellerStoreGroupService.createGroupAgain(storeId);
    }



}
